package com.zzty.dendi.service;

import com.zzty.dendi.entity.User;
import com.zzty.dendi.entity.UserPage;
import com.zzty.dendi.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    UserMapper userMapper;

    @Value("${pageSize}")
    Integer pageSize;
    @Override
    public UserPage getUserByPageNo(Integer pageNo) {
        List<User> users=userMapper.getUserByPageNo((pageNo-1)*pageSize);
        UserPage userPage=new UserPage();
        userPage.setUsers(users);
        userPage.setCurrentPage(pageNo);

        userPage.setTotalPageNo(getTotalPageNo());
        return userPage;
    }

    public int getTotalPageNo(){
        int totalNum=userMapper.getTotalCount();
        return (int)Math.ceil(totalNum/pageSize);
    }


}
